import numpy as np
import cv2

def generate_gradient(img_name, input_path, temp_path):
    img = cv2.imread(img_name)         
    height, width, n = img.shape  

    r = np.tile(np.linspace(100, 255, height, dtype = np.uint8), (width,1)).T
    g = np.tile(np.linspace(100, 255, width, dtype = np.uint8), (height,1))
    b = np.ones((height, width), dtype=np.uint8) * 224
    im = np.dstack((r,g,b))
    # Image.fromarray(im, mode='RGB').show()

    if img_name.endswith(".jpg"):
        save_name = temp_path + str(img_name).replace('.jpg', '_gradient.jpg').replace(input_path, '')
    if img_name.endswith(".png"):
        save_name = temp_path + str(img_name).replace('.png', '_gradient.jpg').replace(input_path, '')

    cv2.imwrite(save_name, im)
